package com.common.www.controller.project;

import com.common.www.bean.entity.Result;
import com.common.www.bean.entity.project.SupplyCompany;
import com.common.www.bean.entity.project.XfgcBiddingCompany;
import com.common.www.bean.entity.tabulation.XfgcBidBaseTabulation;
import com.common.www.bean.entity.tabulation.XfgcTabulation;
import com.common.www.bean.vo.xfgc.StatisticalXfgcBiddingVo;
import com.common.www.bean.vo.xfgc.XfgcComparisonOfClassificationCollectVo;
import com.common.www.bean.vo.xfgc.XfgcComprehensiveUnitPriceCollectVo;
import com.common.www.bean.vo.xfgc.XfgcTabulationExtractingVo;
import com.common.www.service.project.*;
import com.common.www.service.tabulation.*;
import com.common.www.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;


@CrossOrigin
@RestController
@RequestMapping(value = {"mgt/statisticalXfgc"})
@Api(tags = "MGT 消防工程统计分析管理接口")
public class MGTStatisticalAnalysisXfgcController {
    @Autowired
    private XfgcBiddingCompanyService biddingCompanyService;
    @Autowired
    private XfgcBidBaseTabulationService xfgcBidBaseTabulationService;
    @Autowired
    private XfgcTabulationService xfgcTabulationService;
    @Autowired
    private StatisticalAnalysisXfgcService analysisXfgcService;
    @Autowired
    private SupplyCompanyService supplyCompanyService;


    @ApiOperation(value = "供应商等组合信息-排名", nickname = "", notes = "")
    @ApiImplicitParams(value = {
    })
    @RequestMapping(value = "/getRankingProcess", produces = {"application/json"}, method = RequestMethod.POST)
    public Result getRankingProcess(Long projectId) throws InvocationTargetException, IllegalAccessException {
        List<Map<String, Object>> paiMingList = new ArrayList<>();
        HashMap hashMap = new HashMap();
        hashMap.put("xfgcBiddingCompany.project.id", projectId);
        //查询在回标1到回标3的数据
        hashMap.put("jieDuan_ge", 2);
        hashMap.put("jieDuan_le", 4);
        hashMap.put("flag", 1);
        List<XfgcTabulation> extractingList = xfgcTabulationService.getListLogic(hashMap, null);
        //查询标底
        HashMap hashMap1 = new HashMap();
        hashMap1.put("project.id", projectId);
        hashMap1.put("jieDuan", 1);
        hashMap1.put("flag", 1);
        List<XfgcBidBaseTabulation> extractingBdList = xfgcBidBaseTabulationService.getListLogic(hashMap1, null);

        //标底数据准备
        List<XfgcBidBaseTabulation> kzzjBdList = new ArrayList<>();
        List<XfgcBidBaseTabulation> xfbfBdList = new ArrayList<>();
        XfgcTabulationExtractingVo kzzjBdVo = new XfgcTabulationExtractingVo();
        XfgcTabulationExtractingVo xfbfBdVo = new XfgcTabulationExtractingVo();
        XfgcTabulationExtractingVo bdzjVo = new XfgcTabulationExtractingVo();
        BigDecimal hsBaoJiaBdZongHe = BigDecimal.ZERO; // 初始化为0
        BigDecimal bhsBaoJiaBdZongHe = BigDecimal.ZERO; // 初始化为0
        BigDecimal hsBaoJiaBdKzzj = BigDecimal.ZERO; // 初始化为0
        BigDecimal hsBaoJiaBdXfbf = BigDecimal.ZERO; // 初始化为0
        BigDecimal bhsBaoJiaBdKzzj = BigDecimal.ZERO; // 初始化为0
        BigDecimal bhsBaoJiaBdXfbf = BigDecimal.ZERO; // 初始化为0
        BigDecimal shuiLv = extractingBdList.size() > 0 ? extractingBdList.get(0).getShuiJinFillIn() : BigDecimal.ZERO;
        //分开标底抗震支架、消防部分数据
        for (XfgcBidBaseTabulation t : extractingBdList) {
            if ("抗震支架系统".equals(t.getNameType1()) && "KZZJ".equals(t.getCodeNumberType())) {
                hsBaoJiaBdKzzj = hsBaoJiaBdKzzj.add(t.getTotalPriceHs());
                kzzjBdList.add(t);
            } else {
                hsBaoJiaBdXfbf = hsBaoJiaBdXfbf.add(t.getTotalPriceHs());
                xfbfBdList.add(t);
            }
        }
        //数据总计并转换
        hsBaoJiaBdZongHe = hsBaoJiaBdKzzj.add(hsBaoJiaBdXfbf);
        bhsBaoJiaBdZongHe = hsBaoJiaBdZongHe.divide(shuiLv.add(BigDecimal.ONE), 4, RoundingMode.HALF_UP);
        bhsBaoJiaBdKzzj = hsBaoJiaBdKzzj.divide(shuiLv.add(BigDecimal.ONE), 4, RoundingMode.HALF_UP);
        bhsBaoJiaBdXfbf = hsBaoJiaBdXfbf.divide(shuiLv.add(BigDecimal.ONE), 4, RoundingMode.HALF_UP);
        if (kzzjBdList.size() > 0) {
            kzzjBdVo.setProject(kzzjBdList.get(0).getProject());
            kzzjBdVo.setJieDuan(1);
            kzzjBdVo.setHsBaoJia(hsBaoJiaBdKzzj);
            kzzjBdVo.setBhsBaoJia(bhsBaoJiaBdKzzj);
            kzzjBdVo.setShuiLv(shuiLv);
        }
        if (xfbfBdList.size() > 0) {
            xfbfBdVo.setProject(xfbfBdList.get(0).getProject());
            xfbfBdVo.setJieDuan(1);
            xfbfBdVo.setHsBaoJia(hsBaoJiaBdXfbf);
            xfbfBdVo.setBhsBaoJia(bhsBaoJiaBdXfbf);
            xfbfBdVo.setShuiLv(shuiLv);
        }
        bdzjVo.setProject(extractingBdList.size() > 0 ? extractingBdList.get(0).getProject() : null);
        bdzjVo.setJieDuan(1);
        bdzjVo.setBhsBaoJia(bhsBaoJiaBdZongHe);
        bdzjVo.setHsBaoJia(hsBaoJiaBdZongHe);
        bdzjVo.setShuiLv(shuiLv);

        //将回标清单数据按供应商分组
        Map<Long, List<XfgcTabulation>> nameList = extractingList.stream().collect(Collectors.groupingBy(vo -> vo.getXfgcBiddingCompany().getId()));
        for (Map.Entry<Long, List<XfgcTabulation>> item : nameList.entrySet()) {
            //每个供应商数据返回准备
            Map<String, Object> tempMap = new HashMap<>();
            StatisticalXfgcBiddingVo tempKzzj1 = new StatisticalXfgcBiddingVo();
            StatisticalXfgcBiddingVo tempKzzj2 = new StatisticalXfgcBiddingVo();
            StatisticalXfgcBiddingVo tempKzzj3 = new StatisticalXfgcBiddingVo();
            StatisticalXfgcBiddingVo tempXfbf1 = new StatisticalXfgcBiddingVo();
            StatisticalXfgcBiddingVo tempXfbf2 = new StatisticalXfgcBiddingVo();
            StatisticalXfgcBiddingVo tempXfbf3 = new StatisticalXfgcBiddingVo();
            StatisticalXfgcBiddingVo tempItem1 = new StatisticalXfgcBiddingVo();
            StatisticalXfgcBiddingVo tempItem2 = new StatisticalXfgcBiddingVo();
            StatisticalXfgcBiddingVo tempItem3 = new StatisticalXfgcBiddingVo();

            List<XfgcTabulation> value = item.getValue();
            //再按阶段分组
            Map<Integer, List<XfgcTabulation>> valueList = value.stream().collect(Collectors.groupingBy(XfgcTabulation::getJieDuan));
            for (Map.Entry<Integer, List<XfgcTabulation>> itemJieDuan : valueList.entrySet()) {
                Integer jieDuan = itemJieDuan.getKey();
                List<XfgcTabulation> valueJieDuan = itemJieDuan.getValue();
                //供应商阶段数据准备
                List<XfgcTabulation> kzzjList = new ArrayList<>();
                List<XfgcTabulation> xfbfList = new ArrayList<>();
                XfgcTabulationExtractingVo kzzjVo = new XfgcTabulationExtractingVo();
                XfgcTabulationExtractingVo xfbfVo = new XfgcTabulationExtractingVo();
                BigDecimal hsBaoJiaZongHe = BigDecimal.ZERO; // 初始化为0
                BigDecimal bhsBaoJiaZongHe = BigDecimal.ZERO; // 初始化为0
                BigDecimal hsBaoJiaKzzj = BigDecimal.ZERO; // 初始化为0
                BigDecimal hsBaoJiaXfbf = BigDecimal.ZERO; // 初始化为0
                BigDecimal bhsBaoJiaKzzj = BigDecimal.ZERO; // 初始化为0
                BigDecimal bhsBaoJiaXfbf = BigDecimal.ZERO; // 初始化为0
                BigDecimal tempShuiLv = valueJieDuan.size() > 0 ? valueJieDuan.get(0).getShuiJinFillIn() : BigDecimal.ZERO;
                //分开标底抗震支架、消防部分数据
                for (XfgcTabulation vt : valueJieDuan) {
                    if ("抗震支架系统".equals(vt.getNameType1()) && "KZZJ".equals(vt.getCodeNumberType())) {
                        if (Objects.nonNull(vt.getTotalPriceHs())) {
                            hsBaoJiaKzzj = hsBaoJiaKzzj.add(vt.getTotalPriceHs());
                        }
                        kzzjList.add(vt);
                    } else {
                        if (Objects.nonNull(vt.getTotalPriceHs())) {
                            hsBaoJiaXfbf = hsBaoJiaXfbf.add(vt.getTotalPriceHs());
                        }
                        xfbfList.add(vt);
                    }
                }
                //数据总计并转换
                hsBaoJiaZongHe = hsBaoJiaKzzj.add(hsBaoJiaXfbf);
                bhsBaoJiaZongHe = hsBaoJiaZongHe.divide(tempShuiLv.add(BigDecimal.ONE), 4, RoundingMode.HALF_UP);
                bhsBaoJiaKzzj = hsBaoJiaKzzj.divide(tempShuiLv.add(BigDecimal.ONE), 4, RoundingMode.HALF_UP);
                bhsBaoJiaXfbf = hsBaoJiaXfbf.divide(tempShuiLv.add(BigDecimal.ONE), 4, RoundingMode.HALF_UP);
                if (kzzjList.size() > 0) {
                    kzzjVo.setProject(kzzjList.get(0).getXfgcBiddingCompany().getProject());
                    kzzjVo.setJieDuan(jieDuan);
                    kzzjVo.setHsBaoJia(hsBaoJiaKzzj);
                    kzzjVo.setBhsBaoJia(bhsBaoJiaKzzj);
                    kzzjVo.setShuiLv(tempShuiLv);
                    kzzjVo.setXfgcBiddingCompany(kzzjList.get(0).getXfgcBiddingCompany());
                    kzzjVo.setSupplyCompany(xfbfList.get(0).getXfgcBiddingCompany().getSupplyCompany());
                }
                if (xfbfList.size() > 0) {
                    xfbfVo.setProject(xfbfList.get(0).getXfgcBiddingCompany().getProject());
                    xfbfVo.setJieDuan(jieDuan);
                    xfbfVo.setHsBaoJia(hsBaoJiaXfbf);
                    xfbfVo.setBhsBaoJia(bhsBaoJiaXfbf);
                    xfbfVo.setShuiLv(tempShuiLv);
                    xfbfVo.setXfgcBiddingCompany(xfbfList.get(0).getXfgcBiddingCompany());
                    xfbfVo.setSupplyCompany(xfbfList.get(0).getXfgcBiddingCompany().getSupplyCompany());
                }
                //当前供应商对应阶段合价准备
                XfgcTabulationExtractingVo tempVo = new XfgcTabulationExtractingVo();
                tempVo.setProject(valueJieDuan.get(0).getXfgcBiddingCompany().getProject());
                tempVo.setJieDuan(jieDuan);
                tempVo.setHsBaoJia(hsBaoJiaZongHe);
                tempVo.setBhsBaoJia(bhsBaoJiaZongHe);
                tempVo.setShuiLv(tempShuiLv);
                tempVo.setXfgcBiddingCompany(valueJieDuan.get(0).getXfgcBiddingCompany());
                tempVo.setSupplyCompany(valueJieDuan.get(0).getXfgcBiddingCompany().getSupplyCompany());
                //当前阶段排名
                if (jieDuan == 2) {
                    //抗震支架
                    List<XfgcTabulationExtractingVo> tabulationExtractingList1 = analysisXfgcService.getAllXfgcTabulationExtracting(projectId, 2, 1);
                    tempKzzj1 = analysisXfgcService.getPaiMing(tabulationExtractingList1, kzzjVo, kzzjBdVo, 1);
                    //消防部分
                    List<XfgcTabulationExtractingVo> tabulationExtractingList2 = analysisXfgcService.getAllXfgcTabulationExtracting(projectId, 2, 2);
                    tempXfbf1 = analysisXfgcService.getPaiMing(tabulationExtractingList2, xfbfVo, xfbfBdVo, 2);
                    //合价
                    List<XfgcTabulationExtractingVo> tabulationExtractingList3 = analysisXfgcService.getAllXfgcTabulationExtracting(projectId, 2, 3);
                    tempItem1 = analysisXfgcService.getPaiMing(tabulationExtractingList3, tempVo, bdzjVo, 3);
                }
                if (jieDuan == 3) {
                    //抗震支架
                    List<XfgcTabulationExtractingVo> tabulationExtractingList1 = analysisXfgcService.getAllXfgcTabulationExtracting(projectId, 3, 1);
                    tempKzzj2 = analysisXfgcService.getPaiMing(tabulationExtractingList1, kzzjVo, kzzjBdVo, 1);
                    BigDecimal chaYiLvKzzj = BigDecimal.ZERO;
                    if (tempKzzj1.getBhsBaoJia() != null && tempKzzj1.getBhsBaoJia().longValue() > 0) {
                        chaYiLvKzzj = kzzjVo.getBhsBaoJia().subtract(tempKzzj1.getBhsBaoJia()).divide(tempKzzj1.getBhsBaoJia(), RoundingMode.HALF_UP);
                    }
                    tempKzzj2.setChaYiLv(chaYiLvKzzj);
                    //消防部分
                    List<XfgcTabulationExtractingVo> tabulationExtractingList2 = analysisXfgcService.getAllXfgcTabulationExtracting(projectId, 3, 2);
                    tempXfbf2 = analysisXfgcService.getPaiMing(tabulationExtractingList2, xfbfVo, xfbfBdVo, 2);
                    BigDecimal chaYiLvXfbf = BigDecimal.ZERO;
                    if (tempXfbf1.getBhsBaoJia() != null && tempXfbf1.getBhsBaoJia().longValue() > 0) {
                        chaYiLvXfbf = xfbfVo.getBhsBaoJia().subtract(tempXfbf1.getBhsBaoJia()).divide(tempXfbf1.getBhsBaoJia(), RoundingMode.HALF_UP);
                    }
                    tempXfbf2.setChaYiLv(chaYiLvXfbf);
                    //合价
                    List<XfgcTabulationExtractingVo> tabulationExtractingList3 = analysisXfgcService.getAllXfgcTabulationExtracting(projectId, 3, 3);
                    tempItem2 = analysisXfgcService.getPaiMing(tabulationExtractingList3, tempVo, bdzjVo, 3);
                    BigDecimal chaYiLv = BigDecimal.ZERO;
                    if (tempItem1.getBhsBaoJia() != null && tempItem1.getBhsBaoJia().longValue() > 0) {
                        chaYiLv = tempVo.getBhsBaoJia().subtract(tempItem1.getBhsBaoJia()).divide(tempItem1.getBhsBaoJia(), RoundingMode.HALF_UP);
                    }
                    tempItem2.setChaYiLv(chaYiLv);
                }
                if (jieDuan == 4) {
                    //抗震支架
                    List<XfgcTabulationExtractingVo> tabulationExtractingList1 = analysisXfgcService.getAllXfgcTabulationExtracting(projectId, 4, 1);
                    tempKzzj3 = analysisXfgcService.getPaiMing(tabulationExtractingList1, kzzjVo, kzzjBdVo, 1);
                    BigDecimal chaYiLvKzzj = BigDecimal.ZERO;
                    if (tempKzzj2.getBhsBaoJia() != null && tempKzzj2.getBhsBaoJia().longValue() > 0) {
                        chaYiLvKzzj = kzzjVo.getBhsBaoJia().subtract(tempKzzj2.getBhsBaoJia()).divide(tempKzzj2.getBhsBaoJia(), RoundingMode.HALF_UP);
                    }
                    tempKzzj3.setChaYiLv(chaYiLvKzzj);
                    //消防部分
                    List<XfgcTabulationExtractingVo> tabulationExtractingList2 = analysisXfgcService.getAllXfgcTabulationExtracting(projectId, 4, 2);
                    tempXfbf3 = analysisXfgcService.getPaiMing(tabulationExtractingList2, xfbfVo, xfbfBdVo, 2);
                    BigDecimal chaYiLvXfbf = BigDecimal.ZERO;
                    if (tempXfbf2.getBhsBaoJia() != null && tempXfbf2.getBhsBaoJia().longValue() > 0) {
                        chaYiLvXfbf = xfbfVo.getBhsBaoJia().subtract(tempXfbf2.getBhsBaoJia()).divide(tempXfbf2.getBhsBaoJia(), RoundingMode.HALF_UP);
                    }
                    tempXfbf3.setChaYiLv(chaYiLvXfbf);
                    //合价
                    List<XfgcTabulationExtractingVo> tabulationExtractingList3 = analysisXfgcService.getAllXfgcTabulationExtracting(projectId, 4, 3);
                    tempItem2 = analysisXfgcService.getPaiMing(tabulationExtractingList3, tempVo, bdzjVo, 3);
                    BigDecimal chaYiLv = BigDecimal.ZERO;
                    if (tempItem2.getBhsBaoJia() != null && tempItem2.getBhsBaoJia().longValue() > 0) {
                        chaYiLv = tempItem3.getBhsBaoJia().subtract(tempItem2.getBhsBaoJia()).divide(tempItem2.getBhsBaoJia(), RoundingMode.HALF_UP);
                    }
                    tempItem3.setChaYiLv(chaYiLv);
                }
            }
            tempMap.put("supplyCompany", value.get(0).getXfgcBiddingCompany().getSupplyCompany());
            tempMap.put("kzzjBdVo", kzzjBdVo);
            tempMap.put("xfbfBdVo", xfbfBdVo);
            tempMap.put("bdzjVo", bdzjVo);
            tempMap.put("tempKzzj1", tempKzzj1);
            tempMap.put("tempKzzj2", tempKzzj2);
            tempMap.put("tempKzzj3", tempKzzj3);
            tempMap.put("tempXfbf1", tempXfbf1);
            tempMap.put("tempXfbf2", tempXfbf2);
            tempMap.put("tempXfbf3", tempXfbf3);
            tempMap.put("tempItem1", tempItem1);
            tempMap.put("tempItem2", tempItem2);
            tempMap.put("tempItem3", tempItem3);
            paiMingList.add(tempMap);
        }

        return R.ok(paiMingList);
    }


    @ApiOperation(value = "综合单价横向对比分析", nickname = "", notes = "")
    @ApiImplicitParams(value = {
    })
    @RequestMapping(value = "/getComprehensiveUnitPrice", produces = {"application/json"}, method = RequestMethod.POST)
    public Result getComprehensiveUnitPrice(Long projectId, Integer jieDuan) throws InvocationTargetException, IllegalAccessException {
        HashMap hashMap = new HashMap();
        hashMap.put("project.id", projectId);
        List<XfgcBiddingCompany> companyList = biddingCompanyService.getListLogic(hashMap, null);

        List<XfgcComprehensiveUnitPriceCollectVo> sortedList = analysisXfgcService.getComprehensiveUnitPrice(companyList, projectId, jieDuan);
        return R.ok(sortedList);
    }


    @ApiOperation(value = "综合单价横向对比分析-查看单个供应商", nickname = "", notes = "")
    @ApiImplicitParams(value = {
    })
    @RequestMapping(value = "/getComprehensiveUnitPriceOne", produces = {"application/json"}, method = RequestMethod.POST)
    public Result getComprehensiveUnitPriceOne(Long projectId, Integer jieDuan, Long supplyCompanyId) throws InvocationTargetException, IllegalAccessException {
        HashMap hashMap = new HashMap();
        hashMap.put("project.id", projectId);
        List<XfgcBiddingCompany> companyList = biddingCompanyService.getListLogic(hashMap, null);
        SupplyCompany supplyCompany = supplyCompanyService.findOne(supplyCompanyId);
        hashMap.put("supplyCompany.id", supplyCompanyId);
        List<XfgcBiddingCompany> companyItemList = biddingCompanyService.getListLogic(hashMap, null);

        //综合单价对比分析
        List<XfgcComprehensiveUnitPriceCollectVo> tempList = analysisXfgcService.getComprehensiveUnitPrice(companyList, projectId, jieDuan);
        List<XfgcComprehensiveUnitPriceCollectVo> toList = analysisXfgcService.getComprehensiveUnitPriceOne(tempList, supplyCompany, companyItemList, jieDuan);

        return R.ok(toList);
    }


    @ApiOperation("导出综合单价横向对比内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "String", defaultValue = ""),
    })
    @RequestMapping(value = "/exportZhdb", method = RequestMethod.GET)
    public Result exportZhdj(Long projectId, Integer jieDuan) throws InvocationTargetException, IllegalAccessException {
        HashMap hashMap = new HashMap();
        hashMap.put("project.id", projectId);
        List<XfgcBiddingCompany> companyList = biddingCompanyService.getListLogic(hashMap, null);

        List<XfgcComprehensiveUnitPriceCollectVo> sortedList = analysisXfgcService.getComprehensiveUnitPrice(companyList, projectId, jieDuan);
        String fileName = companyList.get(0).getProject().getName();
        XSSFWorkbook workbook = analysisXfgcService.exportZhdj(sortedList);
        HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
        try {
            ServletOutputStream outputStream = response.getOutputStream();
            response.setContentType("application/binary;charset=UTF-8");
            response.setHeader("Content-Disposition", "attachment;fileName="
                    + URLEncoder.encode(fileName + "综合单价横向对比-导出.xlsx", "UTF-8"));
            response.setHeader("Pragma", "No-cache");
            workbook.write(outputStream);
            outputStream.flush();
            outputStream.close();
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (workbook != null) {
                    workbook.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return R.fail("导出错误");
    }


    @ApiOperation(value = "消防-投标报价横向对比", nickname = "", notes = "")
    @ApiImplicitParams(value = {
    })
    @RequestMapping(value = "/getComparisonOfClassification", produces = {"application/json"}, method = RequestMethod.POST)
    public Result getComparisonOfClassification(Long projectId, Integer jieDuan) throws InvocationTargetException, IllegalAccessException {
        HashMap hashMap = new HashMap();
        hashMap.put("project.id", projectId);
        List<XfgcBiddingCompany> companyList = biddingCompanyService.getListLogic(hashMap, null);

        List<XfgcComparisonOfClassificationCollectVo> sortedList = analysisXfgcService.getComparisonOfClassification(companyList, projectId, jieDuan);
        return R.ok(sortedList);
    }


    @ApiOperation(value = "消防-投标报价横向对比查看单个供应商", nickname = "", notes = "")
    @ApiImplicitParams(value = {
    })
    @RequestMapping(value = "/getComparisonOfClassificationOne", produces = {"application/json"}, method = RequestMethod.POST)
    public Result getComparisonOfClassificationOne(Long projectId, Integer jieDuan, Long supplyCompanyId) throws InvocationTargetException, IllegalAccessException {
        HashMap hashMap = new HashMap();
        hashMap.put("project.id", projectId);
        List<XfgcBiddingCompany> companyList = biddingCompanyService.getListLogic(hashMap, null);

        SupplyCompany supplyCompany = supplyCompanyService.findOne(supplyCompanyId);
        hashMap.put("supplyCompany.id", supplyCompanyId);
        List<XfgcBiddingCompany> companyItemList = biddingCompanyService.getListLogic(hashMap, null);
        List<XfgcComparisonOfClassificationCollectVo> tempList = analysisXfgcService.getComparisonOfClassification(companyList, projectId, jieDuan);
        List<XfgcComparisonOfClassificationCollectVo> toList = analysisXfgcService.getComparisonOfClassificationOne(tempList, supplyCompany, companyItemList, jieDuan);
        return R.ok(toList);
    }


    @ApiOperation("导出投标报价横向对比内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "String", defaultValue = ""),
    })
    @RequestMapping(value = "/exportHxdb", method = RequestMethod.GET)
    public Result exportHxdb(Long projectId, Integer jieDuan) {
        HashMap hashMap = new HashMap();
        hashMap.put("project.id", projectId);
        List<XfgcBiddingCompany> companyList = biddingCompanyService.getListLogic(hashMap, null);

        List<XfgcComparisonOfClassificationCollectVo> sortedList = analysisXfgcService.getComparisonOfClassification(companyList, projectId, jieDuan);
        //开始导出
        String fileName = companyList.get(0).getProject().getName();
        XSSFWorkbook workbook = analysisXfgcService.exportHxdb(sortedList);
        HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
        try {
            ServletOutputStream outputStream = response.getOutputStream();
            response.setContentType("application/binary;charset=UTF-8");
            response.setHeader("Content-Disposition", "attachment;fileName="
                    + URLEncoder.encode(fileName + "投标报价横向对比-导出.xlsx", "UTF-8"));
            response.setHeader("Pragma", "No-cache");
            workbook.write(outputStream);
            outputStream.flush();
            outputStream.close();
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (workbook != null) {
                    workbook.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return R.fail("导出错误");
    }

}

